<?php
class PrintUtils extends CApplicationComponent{

public function executeReport($paramsInput, $fileJasper, $fileName, $reportPath){

include dirname(__FILE__).'/Setting.php';    
                
      require_once("http://".$databaseAddress.":8080/JavaBridge/java/Java.inc");

      $class = new JavaClass("java.lang.Class");
      $class->forName("org.postgresql.Driver");
      $driverManager = new JavaClass("java.sql.DriverManager");

      $databaseAddress = "jdbc:postgresql://".$databaseAddress.":".$port."/".$databaseName;
      
      $conn = $driverManager->getConnection($databaseAddress, $userName, $password);

      $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
      $report = $compileManager->compileReport(realpath(Yii::app()->basePath.'/agra/report/'.$fileJasper));
      $fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");

      $paramsInput["SUBREPORT_DIR"] = $reportDirectory.$reportPath.$slash;
      $params = new Java("java.util.HashMap");
      foreach($paramsInput as $key => $value):
      $params->put($key, $value);
      endforeach;
      $emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");

      $jasperPrint = $fillManager->fillReport($report, $params, $conn);
      $exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
      $outputPath = realpath(Yii::app()->basePath).'/agra/temp/'.$fileName.'.pdf';
      $exportManager->exportReportToPdfFile($jasperPrint, $outputPath);

      header("Content-type: application/pdf");
      header("Content-disposition: attachment; filename=\"".$fileName.".pdf\"");
      readfile($outputPath);
      unlink($outputPath);  
      
}
 
}
?>	